'''
Created on 2009-11-14

@author: wenjinjin@gmail.com
'''
from google.appengine.ext import db

from mod.member import Member
from mod.tag import Tag

class Blog(db.Model):
    '''
    classdocs
    '''
    topblog = db.StringProperty(default='')
    author = db.ReferenceProperty(Member)
    createtime = db.DateTimeProperty(auto_now_add=True)
    content = db.StringProperty(multiline=True)
    commentnum = db.IntegerProperty(default=0)
    favoritenum = db.IntegerProperty(default=0)
    noname = db.IntegerProperty(default = 0)
    def blogSave(self):
        if self.topblog != "":
            pblog = db.get(self.topblog)
            pblog.commentnum = pblog.commentnum + 1
            pblog.save()
        self.save()
    
    def blogDelete(self):
        if self.topblog != "":
            pblog = db.get(self.topblog)
            pblog.commentnum = pblog.commentnum - 1
            pblog.save()
        self.delete()
    
    def incrFavNum(self):
        self.favoritenum += 1
        self.put()
    def subFavNum(self):
        self.favoritenum -= 1
        self.favoritenum = self.favoritenum<0 and 0 or self.favoritenum
        self.put()
    